package com.ruslan.magaz.web.validation;

import java.lang.annotation.Annotation;
import java.util.List;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.springframework.beans.factory.annotation.Autowired;

import com.ruslan.magaz.domain.OrderedItem;
import com.ruslan.magaz.domain.User;
import com.ruslan.magaz.service.UserService;

public class ValidCountValidator implements
		ConstraintValidator<ValidCount, List<OrderedItem>> {

	@Autowired
	private UserService userService;

	@Override
	public void initialize(ValidCount constraint) {

	}

	@Override
	public boolean isValid(List<OrderedItem> orderedItems, ConstraintValidatorContext context) {
		for (OrderedItem orderedItem: orderedItems){
			if (orderedItem.getProductQuantity()<0 || orderedItem.getProductQuantity()>1000){
				return false;
			}
		}
		return true;
	}
	
	

}